<template>
	<view class="generalManager-box">
		<view class="order-top">
			<view  class="top-left-box">
				<view class="top-left" @tap="personal">
					<image class="person" src="/static/images/zjl.png"></image>
					<text>总经理</text>
				</view>
				<view class="top-right" @tap="search">
					<image class="search" src="/static/images/search.png" mode=""></image>
					<input type="text" value=""  disabled="true" class="search-input" placeholder="订单编号搜索" placeholder-class="sty" />
					
				</view>
			</view>
			<view class="top-right-box ">
			
				<!-- 消息 -->
				<view class="message-img " @tap="skipToMessage">
					<image class="message-img-icon" src="/static/images/message01.png"  mode=""></image>
					<view class=" info-num" v-if="messagenumber!=0">{{messagenumber}}</view>
				</view>
				
			</view>
			
		</view>
		
		<view class="sz-box" @tap="jump">
			<view class="title">
				赊账订单审核
			</view>
			
			<view class="sz-right">
				<text class="tap">{{checkOrder}}</text>
				<image class="you" src="/static/images/you.png" mode=""></image>
			</view>
		</view>
		
		
		<view class="warehouse" v-for="(item,index) in deptVosList">
			<!-- 这个版本不上线 -->
			<!-- <view class="warehouse-title"  @click="skipToCalc(item)"> -->
			<view class="warehouse-title"  >
				<image class="shops" src="/static/images/shops.png" mode=""></image>{{item.name}}
			</view>
			
			<view class="warehouse-list" v-for="(iitem,iindex) in item.users">
				<view class="list" @tap="salesman(iitem)">
					<view class="salesman-name">
						{{iitem.nickName}}
					</view>
					<view class="salesman-number">
						{{iitem.salesmanNo}}
					</view>
					
					<image class="you" src="/static/images/zuoc.png" mode=""></image>
				</view>
			</view>
		</view>
	
	
	<view class="js-drop" v-if="sj">
		  <view class="js-box" style="background: url(../../static/images/upgrade.png) no-repeat center; background-size: 100% 100%; ">
			  <view class="version">V{{version}}</view>
			  
			  <image class="js-close" v-if="!constraint" @tap="sjClose" src="../../static/images/sjclose.png"></image>
			  <scroll-view class="js-scroll" scroll-y="true" >
			  	<view class="js-list" v-for="(item,index) in bugList">
			  		 {{item}}
			  	</view>
			  </scroll-view>
			  
			  <view class="btn" @tap="upgrade">立即更新</view>
		  </view>
	  </view> 
	</view>
</template>

<script>
	// 
	const util = require("../../utils/util.js");
	//获取应用实例
	const api = require("../../config/api.js"); 
	export default {
		data() {
			return {
				deptVosList:[],
				checkOrder:0,
				sj:false,
				bugList:'',
				version:'',
				constraint:false,
				downloadUrl:'',
				messagenumber:"",
				
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.managerIndex()
			// 请求消息列表
			this.getInfo();
			
		},
		onLoad(){
			//#ifdef APP-PLUS
			// 检测升级
			  util.request(api.appversionCheck, {}, "POST").then((res)=>{
						console.log(res)
						// 强制升级
						if(res.error==90){
							console.log('升级')
							 this.sj = true
							 this.downloadUrl = res.data.downloadUrl;
							// 判断是否强制升级
							 this.constraint=true;
							 this.bugList = res.data.remark.split('|');
							 this.version = res.data.version;
							  console.log(this.bugList)
						}else if(res.error==91){
							// 选择升级 
							 this.sj = true
							 this.downloadUrl = res.data.downloadUrl;
							 this.bugList = res.data.remark.split('|');
							 this.version = res.data.version;
							 console.log(this.bugList )
						}
						
						console.log(!this.sj)
						if(!this.sj){
							// 判断是否登录
							var isLogin = uni.getStorageSync('isLogin');
							if(!isLogin){
								uni.redirectTo({
									url: '/pages/login/login'
								})
							}
						}
			  })
			 //#endif  
		},
		onShow() {
			console.log(123456789)
			
			this.managerIndex();
			// 请求消息列表
			this.getInfo();
		},
		methods: {
			// 获取维度消息
			getInfo() {
				var _that = this;
				util.request(api.messageResume, {}, ).then((res) => {
					//console.log('消息中心',JSON.stringify(res));
					if (res.errno === 0) {
						var num = 0;
						var data = res.data;
						for(var i=0;i<data.length;i++){
							num=num+parseInt(data[i].nums)
						}
						_that.messagenumber= num
						
					}
				});
			},
			skipToCalc(obj){
				console.log(obj)
				uni.navigateTo({
					url:"/pages/calc/calc?deptId=" + obj.deptId
				})
			},
			
			skipToMessage(){
				console.log("消息");
				uni.navigateTo({
					url:"/pages/message/message"
				})
			},
			// 升级
				  upgrade(){
					  console.log(this.constraint)
					  if(this.constraint){
						    plus.runtime.openURL(this.downloadUrl);  
					  }
					
					  
					 
			},
				  // 关闭升级
				  sjClose(){ 
					   this.sj = false
				  },
			search(){
				uni.navigateTo({
					url:"/pages/search/search"
				})
			},
			jump(){
				uni.navigateTo({
					url:"/pages/onAccountCheck/onAccountCheck"
				})
			},
			personal(){
				uni.navigateTo({
					url:"/pages/personalCenter/personalCenter"
				})
			},
			salesman(json){
				console.log("json",json);
				uni.navigateTo({
					url:"/pages/managerSalesman/managerSalesman?user="+JSON.stringify(json)+'&isOrder=1'
				})
			},
			managerIndex(){
				util.request(api.managerIndex, {}, 'GET').then(res => {
					
					if(res.error==0){
						this.checkOrder =  res.data.verifyOrderNum
						this.deptVosList = res.data.deptVos
						
						uni.stopPullDownRefresh()
					}
					console.log(res)
				})
			}
			
			
		}
	}
</script>

<style>
	@import url("./generalManager.css");
</style>
